package com.itboye.mengwu.app.ui.aiwujia;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import com.itboye.core.object.BaseFragment;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.R;
import com.itboye.mengwu.address.AddressFragment;
import com.itboye.mengwu.app.adapter.Item2Adapter;
import com.itboye.mengwu.app.adapter.ItemAdapter;
import com.itboye.mengwu.app.ui.roof.ActivityHomePageSearch;
import com.itboye.mengwu.app.ui.roof.HomePageItemFragmentTypeTwo;
import com.itboye.mengwu.app.ui.roof.TodaySpecialOfferItemFragment;
import com.itboye.mengwu.data.model.HomePageModel;
import com.itboye.mengwu.data.model.LunBoModel;
import com.itboye.mengwu.data.presenter.LunBoPresenter;
import com.itboye.mengwu.main.RoofFragment;
import com.itboye.mengwu.main.RoofFragment.MyAdapter;
import com.itboye.mengwu.widget.FixGridLayout;
import com.itboye.mengwu.widget.PagerSlidingTabStrip;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout.LayoutParams;

public class FragementZenWuXianNew extends BaseFragment implements
		OnItemClickListener, Observer {

	String[] biaoqian_1 = { "亲子", "女装", "童鞋", "婴童用品", "美食", "居家" };
	String[] biaoqian_2 = { "亲子2", "女装2", "童鞋2", "婴童用品2", "美食2", "居家2" };

	// PagerSlidingTabStrip tabs;
	// boolean isShow = false;
	// TextView txt_more;

	// LunBoPresenter boPresenter;
	// protected PopupWindow popupWindow;
	RelativeLayout quyuLayout, fenleiLayout, paixuLayout;
	FrameLayout jumpWindow;
	boolean quyuBoo = false, fenleiBoo = false, paixuBoo = false;
	private PopupWindow popupWindow;

	@Override
	public int initView() {

		return R.layout.activity_zengwuxian_new;
	}

	@Override
	public void onMyActivityCreated() {
		// showProgressDialog("数据加载中，请稍后", true);
		setDefaultFragment();

		quyuLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				showPopupQuYuWindow(v);

			}
		});
		fenleiLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				showPopupFenLeiWindow(v);
			}

		});
		paixuLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				showPopupPaiXuWindow(v);
			}

		});

	}

	private void setDefaultFragment() {
		FragmentManager fm = getActivity().getSupportFragmentManager();
		FragmentTransaction transaction = fm.beginTransaction();
		ZengSongListFragment zengSongListFragment = new ZengSongListFragment();
		transaction.replace(R.id.id_content, zengSongListFragment);
		transaction.commit();

	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity model = super.handlerError(data);
		if (model != null) {

		}
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub

	}

	private void showPopupQuYuWindow(View view) {
		

		if (!quyuBoo) {View contentView = LayoutInflater.from(getContext()).inflate(
				R.layout.fragment_quyu, null);

		  popupWindow = new PopupWindow(contentView,
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
			// 一个自定义的布局，作为显示的内容
			popupWindow.setTouchable(true);
			popupWindow.setOutsideTouchable(true);
			popupWindow.showAsDropDown(view);
		} else {
			popupWindow.dismiss();
		}
		quyuBoo = !quyuBoo;

	}

	private void showPopupFenLeiWindow(View v) {
		
		if (!fenleiBoo) {
			ListView big, little;
			View contentView = LayoutInflater.from(getContext()).inflate(
					R.layout.item_fenlei, null);
			  popupWindow = new PopupWindow(contentView,
					LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
			big = (ListView) contentView.findViewById(R.id.big);
			little = (ListView) contentView.findViewById(R.id.little);

			ArrayList<String> strs = new ArrayList<String>();
			strs.add("屋内用品");
			strs.add("厕所用品");
			strs.add("女装");
			strs.add("男装");
			ItemAdapter adapter = new ItemAdapter(getContext(), strs, little);
			Item2Adapter adapte2 = new Item2Adapter(getActivity(), strs);
			big.setAdapter(adapter);
			little.setAdapter(adapte2);

			popupWindow.setTouchable(true);

			popupWindow.setOutsideTouchable(true);
			popupWindow.showAsDropDown(v);
			Log.e("!!!!!!!", "!!!!");
		} else {
			popupWindow.dismiss();
		}
		fenleiBoo = !fenleiBoo;
	}

	private void showPopupPaiXuWindow(View v) {
		// 一个自定义的布局，作为显示的内容
		
		if (!paixuBoo) {
			View contentView = LayoutInflater.from(getContext()).inflate(
					R.layout.fragment_paixu, null);

			  popupWindow = new PopupWindow(contentView,
					LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
			popupWindow.setTouchable(true);
			popupWindow.setOutsideTouchable(true);
			popupWindow.showAsDropDown(v);
		} else {
			popupWindow.dismiss();
		}
		paixuBoo = !paixuBoo;
	}
}
